#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> advantageCount(vector<int>& nums1, vector<int>& nums2) {
    int n = nums1.size();
    vector<int> index(n);
    for (int i = 0; i < n; ++i)
        index[i] = i;

    sort(index.begin(), index.end(), [&](int i, int j) {
        return nums2[i] < nums2[j];
        });

    sort(nums1.begin(), nums1.end());

    vector<int> ret(n);
    int left = 0, right = n - 1;
    for (int i = 0; i < n; ++i)
    {
        if (nums1[i] > nums2[index[left]])
        {
            ret[index[left++]] = nums1[i];
        }
        else
        {
            ret[index[right--]] = nums1[i];
        }
    }


    return ret;
}

int main()
{
    vector<int> n1 = { 12,24,8,32 };
    vector<int> n2 = { 13,25,32,11 };

    advantageCount(n1 , n2);

	return 0;
}